//
//  ExtensionMirror.swift
//  uwantgoeasy
//
//  Created by 冯传宝 on 12/16/15.
//  Copyright © 2015 uwantsoft. All rights reserved.
//

import Foundation

extension Mirror {
    
    func toDictionary() -> [String: AnyObject] {
        var dict = [String: AnyObject]()
        
        // Properties of this instance:
        for attr in self.children {
            if let propertyName = attr.label {
                dict[propertyName] = attr.value as? AnyObject
            }
        }
        
        // Add properties of superclass:
        if let parent = self.superclassMirror() {
            for (propertyName, value) in parent.toDictionary() {
                dict[propertyName] = value
            }
        }
        
        return dict
    }
}